import config from '@/config.js'
import qiniuUploader from '@/utils/qiniuUploader.js'
import md5 from '@/utils/md5.min.js'

export default function uploadFile(filePath,prefix,zip = true) {
	let fp = `${filePath.split('/').pop().split('.')[0]}` + new Date()
	fp  = md5(fp)
	return new Promise((resolve, reject) => {
		qiniuUploader.upload(filePath, (res) => {
			if(zip) {
				res.fileUrl += "-zip"
			}
			resolve(res)
		}, (error) => {
			reject(error)
		}, {
			region: 'NCN',
			domain: 'https://files.jizhixing.top',
			uptokenURL: config.baseUrl + "/wx/getUploadToken",
			key: `${prefix || ''}${fp}`
		})
	})
}